package com.example.dblibrary.app;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.example.dblibrary.mvp.BaseMvp.BaseContract;

//import butterknife.ButterKnife;
//import butterknife.Unbinder;

/**
 * @author jac
 * @date 2018/10/18.
 * Description：
 */
public abstract class BaseActivity<T extends BaseContract.BasePresenter> extends AppCompatActivity implements BaseContract.BaseView {

	protected T presenter;
//	private Unbinder unbinder;

	@Override
	protected void onCreate(@Nullable Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		presenter=bindPresenter(this);
		if(presenter!=null){
			getLifecycle().addObserver(presenter);//为Lifecycle注册生命周期监听器
		}else {
			try {
				throw new Exception("当前未绑定presenter");
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		setContentView(this.getLayoutId());
		initView();
//		unbinder = ButterKnife.bind(this);
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
//		unbinder.unbind();
	}

	/**
	 * 绑定presenter
	 *
	 * @param context
	 * @return
	 */
	public abstract T bindPresenter(Context context);

	/**
	 * 设置布局
	 *
	 * @return
	 */
	public abstract int getLayoutId();

	/**
	 * 初始化视图
	 */
	public abstract void initView();

}
